package com.propic.www;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by geange on 16-4-19.
 */
public class Pictureguide extends Application{

    public static int flag = 0;
    public static List<ImageView> imageViews = new ArrayList<ImageView>();
    public static BorderPane mainpane = new BorderPane();
    public static BorderPane guidepane = new BorderPane();
    public static StackPane cenpane = new StackPane();
    public static Button leftbutton = new Button("前一张");
    public static Button rightbutton = new Button("后一张");
    @Override
    public void start(Stage primaryStage) throws Exception {
//        Parent root = FXMLLoader.load(getClass().getResource("OpensinglePhoto.fxml"));
        guidepane.setLeft(leftbutton);
        guidepane.setRight(rightbutton);
        for(File filetmp : Mainwindows.files){
            Image imgetmp = new Image("file:"+filetmp.getAbsolutePath());
            ImageView imageViewtmp = new ImageView(imgetmp);
            imageViews.add(imageViewtmp);
        }

        leftbutton.setOnAction(e->{
            if(flag>0 || flag<imageViews.size()){
                ImageView imageViewget = imageViews.get(flag-1);
                cenpane.getChildren().clear();
                cenpane.getChildren().add(imageViewget);
                flag = flag - 1;
            }
        });

        rightbutton.setOnAction(e->{
            if (flag>=0 || flag<imageViews.size()){
                ImageView imageViewget = imageViews.get(flag+1);
                cenpane.getChildren().clear();
                cenpane.getChildren().add(imageViewget);
                flag = flag + 1;
            }
        });

//        cenpane.setStyle("-fx-background-color:#272a40");
        cenpane.getChildren().add(imageViews.get(0));
        mainpane.setBottom(guidepane);
        mainpane.setCenter(cenpane);
//        Scene scene = new Scene(root, 1000, 620);
//        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void show(){
        Pictureguide.launch();
    }

    public static void main(String[] args){
        launch(args);
    }
}
